<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언
    $billCd 			    = $_POST['billCd'];
    $issueDt 			    = $_POST['issueDt'];
    $expressCd 			    = $_POST['expressCd'];
    $cargoType 			    = $_POST['cargoType'];
    $expressClass 			= $_POST['expressClass'];
    $destNationCd 			= $_POST['destNationCd'];
    $destAddr 			    = $_POST['destAddr'];
    $destZone 			    = $_POST['destZone'];
    $compCd 			    = $_POST['compCd'];
    $consignee 			    = $_POST['consignee'];
    $item 			        = $_POST['item'];
    $cargoTon 			    = $_POST['cargoTon'];
    $weightTon 			    = $_POST['weightTon'];
    $ratePerWeight 			= $_POST['ratePerWeight'];
    $totalRate 			    = $_POST['totalRate'];
    $totalRatePerWeight 	= $_POST['totalRatePerWeight'];
    $flag 			        = $_POST['flag'];
    $compDCRate 			= $_POST['compDCRate'];
    $compOilRate 			= $_POST['compOilRate'];
    $compDCAmount 			= $_POST['compDCAmount'];
    $compInvAmount 			= $_POST['compInvAmount'];
    $compOilAmount 		    = $_POST['compOilAmount'];
    $compTotalInvAmount 	= $_POST['compTotalInvAmount'];
    $compExtraCharge 	    = $_POST['compExtraCharge'];
    $carrDCRate 			= $_POST['carrDCRate'];
    $carrOilRate 			= $_POST['carrOilRate'];
    $carrDCAmount 			= $_POST['carrDCAmount'];
    $carrInvAmount 			= $_POST['carrInvAmount'];
    $carrOilAmount 			= $_POST['carrOilAmount'];
    $carrTotalInvAmount 	= $_POST['carrTotalInvAmount'];
    $extraCharge 			= $_POST['extraCharge'];
    $profit 			    = $_POST['profit'];
    $remarks 			    = $_POST['remarks'];
    $expressCompCd		    = $_POST['expressCompCd'];

    if($remarks) $remarks = iconvEncode($remarks);

    if(!$weightTon) $weightTon = 0;
    if(!$ratePerWeight) $ratePerWeight = 0;
    if(!$totalRate) $totalRate = 0;
    if(!$totalRatePerWeight) $totalRatePerWeight = 0;
    if(!$compDCRate) $compDCRate = 0;
    if(!$compOilRate) $compOilRate = 0;
    if(!$compDCAmount) $compDCAmount = 0;
    if(!$compInvAmount) $compInvAmount = 0;
    if(!$compOilAmount) $compOilAmount = 0;
    if(!$compTotalInvAmount) $compTotalInvAmount = 0;
    if(!$compExtraCharge) $compExtraCharge = 0;
    if(!$carrDCRate) $carrDCRate = 0;
    if(!$carrOilRate) $carrOilRate = 0;
    if(!$carrDCAmount) $carrDCAmount = 0;
    if(!$carrInvAmount) $carrInvAmount = 0;
    if(!$carrOilAmount) $carrOilAmount = 0;
    if(!$carrTotalInvAmount) $carrTotalInvAmount = 0;
    if(!$extraCharge) $extraCharge = 0;
    if(!$expressCompCd) $expressCompCd = 0;
    if(!$profit) $profit = 0;

//    $stmt = mssql_init('spExpress');

    if(!$issueId) $issueId = "Jade";

    $query = "EXEC spExpress ";

    $query .=" @billCd='" .$billCd ."'";
    $query .=", @issueDt='" .$issueDt ."'";
    $query .=", @expressCd='" .$expressCd ."'";
    $query .=", @cargoType='" .$cargoType ."'";
    $query .=", @expressClass='" .$expressClass ."'";
    $query .=", @destNationCd='" .$destNationCd ."'";
    $query .=", @destAddr='" .$destAddr ."'";
    $query .=", @destZone='" .$destZone ."'";
    $query .=", @compCd='" .$compCd ."'";
    $query .=", @consignee='" .$consignee ."'";
    $query .=", @item='" .$item ."'";
    $query .=", @cargoTon='" .$cargoTon ."'";
    $query .=", @weightTon='" .$weightTon ."'";
    $query .=", @ratePerWeight='" .$ratePerWeight ."'";
    $query .=", @totalRate='" .$totalRate ."'";
    $query .=", @totalRatePerWeight='" .$totalRatePerWeight ."'";
    $query .=", @compDCRate='" .$compDCRate ."'";
    $query .=", @compDCAmount='" .$compDCAmount ."'";
    $query .=", @compOilRate='" .$compOilRate ."'";
    $query .=", @compOilAmount='" .$compOilAmount ."'";
    $query .=", @compInvAmount='" .$compInvAmount ."'";
    $query .=", @compTotalInvAmount='" .$compTotalInvAmount ."'";
    $query .=", @compExtraCharge='" .$compExtraCharge ."'";
    $query .=", @carrDCRate='" .$carrDCRate ."'";
    $query .=", @carrDCAmount='" .$carrDCAmount ."'";
    $query .=", @carrOilRate='" .$carrOilRate ."'";
    $query .=", @carrOilAmount='" .$carrOilAmount ."'";
    $query .=", @carrInvAmount='" .$carrInvAmount ."'";
    $query .=", @carrTotalInvAmount='" .$carrTotalInvAmount ."'";
    $query .=", @extraCharge='" .$extraCharge ."'";
    $query .=", @profit='" .$profit ."'";
    $query .=", @remarks='" .$remarks ."'";
    $query .=", @flag='" .$flag ."'";
    $query .=", @issueId='" .$issueId ."'";
    $query .=", @expressCompCd='" .$expressCompCd ."'";

    $logger->debug($query ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
//    $query = iconvEncode($query);
    $rslt = mssql_query($query);
    $logger->debug($rslt ." [#FROM:" . $G_remote_ip."#]");

    $result = Array();
    if ($rslt == "1") {
        $result['rsStatus'] = "Success";
        $successMsg = iconvEncode("저장 되었습니다.");
    }
    else {
        $result['rsStatus'] = "Fail";
        $successMsg = iconvEncode("저장 실패");

    }
    $result['rsStr'] = urlencode($successMsg);

    $output = json_encode($result);
    $output = urldecode($output);
    echo iconvDecode($output);
    $logger->debug($output ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>